package com.example.project.service.impl;

import com.example.project.dao.TcdmSecureHazardAssessmentDao;
import com.example.project.entity.TcdmSecureHazardAssessment;
import com.example.project.entity.TcdmSecureHazardAssessmentRecycle;
import com.example.project.dao.TcdmSecureHazardAssessmentRecycleDao;
import com.example.project.service.TcdmSecureHazardAssessmentRecycleService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TcdmSecureHazardAssessmentRecycle)表服务实现类
 *
 * @author makejava
 * @since 2024-02-23 15:18:23
 */
@Service("tcdmSecureHazardAssessmentRecycleService")
public class TcdmSecureHazardAssessmentRecycleServiceImpl implements TcdmSecureHazardAssessmentRecycleService {
    @Resource
    private TcdmSecureHazardAssessmentRecycleDao tcdmSecureHazardAssessmentRecycleDao;

    @Resource
    private TcdmSecureHazardAssessmentDao tcdmSecureHazardAssessmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param tshareId 主键
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRecycle queryById(Integer tshareId) {
        return this.tcdmSecureHazardAssessmentRecycleDao.queryById(tshareId);
    }

    @Override
    public List<TcdmSecureHazardAssessmentRecycle> findList() {
        return this.tcdmSecureHazardAssessmentRecycleDao.findList();
    }

    /**
     * 分页查询
     *
     * @param tcdmSecureHazardAssessmentRecycle 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TcdmSecureHazardAssessmentRecycle> queryByPage(TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle, PageRequest pageRequest) {
        long total = this.tcdmSecureHazardAssessmentRecycleDao.count(tcdmSecureHazardAssessmentRecycle);
        return new PageImpl<>(this.tcdmSecureHazardAssessmentRecycleDao.queryAllByLimit(tcdmSecureHazardAssessmentRecycle, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tcdmSecureHazardAssessmentRecycle 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRecycle insert(TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle) {
        this.tcdmSecureHazardAssessmentRecycleDao.insert(tcdmSecureHazardAssessmentRecycle);
        return tcdmSecureHazardAssessmentRecycle;
    }

    /**
     * 修改数据
     *
     * @param tcdmSecureHazardAssessmentRecycle 实例对象
     * @return 实例对象
     */
    @Override
    public TcdmSecureHazardAssessmentRecycle update(TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle) {
        this.tcdmSecureHazardAssessmentRecycleDao.update(tcdmSecureHazardAssessmentRecycle);
        return this.queryById(tcdmSecureHazardAssessmentRecycle.getTshareId());
    }

    /**
     * 通过主键删除数据
     *
     * @param tshareId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer tshareId) {
//        TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle=tcdmSecureHazardAssessmentRecycleDao.queryById(tshareId);
//        TcdmSecureHazardAssessment tcdmSecureHazardAssessment=new TcdmSecureHazardAssessment();
//        tcdmSecureHazardAssessment.setTshaId(tcdmSecureHazardAssessmentRecycle.getTshaId());
//        tcdmSecureHazardAssessment.setValid(1);
//        tcdmSecureHazardAssessmentDao.update(tcdmSecureHazardAssessment);
        TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle=queryById(tshareId);
        this.tcdmSecureHazardAssessmentDao.deleteById(tcdmSecureHazardAssessmentRecycle.getTshaId());
        return this.tcdmSecureHazardAssessmentRecycleDao.deleteById(tshareId) > 0;
    }

    @Override
    public Boolean recover(Integer tshareId) {
        TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle=tcdmSecureHazardAssessmentRecycleDao.queryById(tshareId);
        TcdmSecureHazardAssessment tcdmSecureHazardAssessment=new TcdmSecureHazardAssessment();
        tcdmSecureHazardAssessment.setTshaId(tcdmSecureHazardAssessmentRecycle.getTshaId());
        tcdmSecureHazardAssessment.setValid(1);
        tcdmSecureHazardAssessmentDao.update(tcdmSecureHazardAssessment);
        return this.tcdmSecureHazardAssessmentRecycleDao.deleteById(tshareId) > 0;
    }

    @Override
    public Boolean deleteAll() {
        this.tcdmSecureHazardAssessmentDao.deleteByValid();
        return this.tcdmSecureHazardAssessmentRecycleDao.deleteAll();
    }
}
